<?php


namespace App\Listener;


use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;

class LoggerListener
{

    private $logger;

    /**
     * LoggerListener constructor.
     * @param $logger
     */
    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }


    public function onKernelController(ControllerEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $this->logger->info($event->getRequest()->getRealMethod()." -> ".$event->getRequest()->getUri());
    }

    public function onKernelResponse(ResponseEvent $event)
    {
        $response = $event->getResponse();

        if (!$event->isMasterRequest()) {
            return;
        }

        $this->logger->info("返回数据：{$response->getContent()}");
    }

}